﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace MiniFox.Infrastructure
{
    /// <summary>
    /// 分页查询结果的载体
    /// </summary>
    /// <typeparam name="TResult">结果集类型（IEnumerable 类型）</typeparam>
    [JsonObject]
    public class PagedResultObject<TResult> : ResultObject<TResult>
    {
        int _pageIndex;
        int _pageSize;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="rowCount"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        public PagedResultObject(int rowCount, int pageIndex, int pageSize) : base(rowCount)
        {
            _pageIndex = pageIndex;
            _pageSize = pageSize;
        }

        /// <summary>
        /// 页数
        /// </summary>
        [JsonProperty("pageCount")]
        public int PageCount
        {
            get { return (int)Math.Ceiling((decimal)RowCount / PageSize); }
        }
        /// <summary>
        /// 页码(从1开始)
        /// </summary>
        [JsonProperty("pageIndex")]
        public int PageIndex
        {
            get { return _pageIndex; }
        }
        /// <summary>
        /// 每页记录数
        /// </summary>
        [JsonProperty("pageSize")]
        public int PageSize
        {
            get { return _pageSize; }
        }
    }
}
